package com.crm.business.admin.controller;


import com.alibaba.fastjson.JSONObject;
import com.crm.business.admin.service.IAdminMenuService;
import com.crm.common.admin.common.AdminRoleTypeEnum;
import com.crm.common.admin.entity.VO.AdminMenuVO;
import com.crm.common.ka.core.common.Result;
import com.crm.common.ka.core.common.SubModelType;
import com.crm.common.ka.core.common.log.BehaviorEnum;
import com.crm.common.ka.core.common.log.SysLogHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 后台菜单表 前端控制器
 * </p>
 *
 * @author zhangzhiwei
 * @since 2020-04-27
 */
@RestController
@RequestMapping("/adminMenu")
@Api(tags = "菜单模块")
public class AdminMenuController {

    @Autowired
    private IAdminMenuService adminMenuService;

    @RequestMapping("/getMenuListByType/{type}")
    @ApiOperation("根据类型查询菜单")
    public Result<JSONObject> getMenuListByType(@PathVariable("type") Integer type) {
        JSONObject byType = adminMenuService.getMenuListByType();
        return Result.ok(byType);
    }

    @RequestMapping("/shwoAllMemu")
    @ApiOperation("展示所有menu")
    public Result<JSONObject> shwoAllMemu() {
        JSONObject jsonObject = adminMenuService.shwoAllMemu();
        return Result.ok(jsonObject);
    }

    @RequestMapping("/getWorkMenuList")
    @ApiOperation("查询项目管理菜单")
    public Result<JSONObject> getWorkMenuList() {
        JSONObject byType = adminMenuService.getMenuListByType();
        return Result.ok(byType);
    }

    @RequestMapping("/queryMenuId")
    public Result<Integer> queryMenuId(@RequestParam("realm1") String realm1, @RequestParam("realm2") String realm2,
                                       @RequestParam("realm3") String realm3){
        Integer menuId = adminMenuService.queryMenuId(realm1,realm2,realm3);
        return Result.ok(menuId);

    }

    @RequestMapping("/queryCrmMenu")
    @ApiOperation("查询CRM管理菜单")
    public Result<List<AdminMenuVO>> queryCrmMenu() {
        List<AdminMenuVO> list = adminMenuService.queryCrmMenu();
        return Result.ok(list);
    }

    @RequestMapping("/upMenuStatus")
    @ApiOperation("菜单开关")
    @SysLogHandler(subModel = SubModelType.ADMIN_COMPANY_HOME,behavior = BehaviorEnum.UPDATE,object = "商户配置",detail = "菜单开关")
    public Result upMenuStatus(@RequestParam("menuId") Integer menuId,@RequestParam("status") Integer status){
        adminMenuService.upMenuStatus(menuId,status);
        return Result.ok();
    }
}

